/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.audit.service.impl;

import com.koron.audit.domain.WorkFlowAuxiliary;
import com.koron.audit.mapper.WorkFlowAuxiliaryMapper;
import com.koron.audit.service.api.WorkFlowAuxiliaryService;
import org.koron.ebs.mybatis.SessionFactory;
import org.springframework.stereotype.Service;

@Service
public class WorkFlowAuxiliaryServiceImpl implements WorkFlowAuxiliaryService {

	@SuppressWarnings("deprecation")
	@Override
	public String userCode(String templateKey, String processName, String keyType) {
		try(SessionFactory factory=new SessionFactory()){
			WorkFlowAuxiliaryMapper mapper = factory.getMapper(WorkFlowAuxiliaryMapper.class);
			WorkFlowAuxiliary wfa = mapper.query(templateKey, processName, keyType);
			if(wfa == null){
				return null;
			}
			return wfa.getKeyValue();
		} catch (Exception e) {
			return null;
		}
	}

	@SuppressWarnings("deprecation")
	@Override
	public Integer count(String templateKey, String processName) {
		try(SessionFactory factory=new SessionFactory()){
			WorkFlowAuxiliaryMapper mapper = factory.getMapper(WorkFlowAuxiliaryMapper.class);
			return mapper.count(templateKey, processName);
		} catch (Exception e) {
			return 0;
		}
	}
}
